import { useReactive } from "ahooks";
import { useModel } from "umi";
import { useEffect } from "react";
import compress from "gql-compress";

const useCheckCategoryByCcName = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        categoryLoading: false,
        category: [],
    });

    // 加载所有部门信息, 用树的数据格式
    const checkCategoryName = async (ccName) => {
        state.categoryLoading = true;
        // let res = await graphqlFetch({
        //     query,
        //     variables: {},
        // });
        // let categories = res?.a?.nodes || [];
        let categories = { ccUuid: 1, ccPaid: null, ccName: "一级品类" }

        state.category = categories;
        state.categoryLoading = false;
        return categories;
    };

    useEffect(() => {
        checkCategoryName();
    }, []);

    return { ...state, checkCategoryName };
};

const query = compress(``);

export default useCheckCategoryByCcName;
